<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>文章列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/themes/admin/css/font.css">
        <link rel="stylesheet" href="/themes/admin/css/xadmin.css">
        <link rel="stylesheet" href="/themes/admin/css/common.css">
        <script src="/themes/admin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/themes/admin/js/xadmin.js"></script>
    </head>
    
    <body>
    <div class="x-nav">
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="postCate" lay-filter="postCate" id="postCate">
                                        <option value="">所有分类</option>
                                        {volist name="$cate" id="vo"}
                                        <option value="{$vo.cate_id}">{$vo.cate_name}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="postStatus" lay-filter="postStatus">
                                        <option value="">状态</option>
                                        <option value="0">公开</option>
                                        <option value="1">私密</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" id="postKeyword" placeholder="请输入关键字" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button type="button" class="layui-btn"  id="btn-search">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                                <i class="layui-icon"></i>批量删除
                            </button>
                            <a href="/admin/post/postAdd" class="layui-btn layui-btn-normal">发布文章</a>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                                <thead>
                                    <tr>
                                        <th>
                                            <input type="checkbox" name="" lay-filter="checkall" lay-skin="primary">
                                        </th>
                                        <th>ID</th>
                                        <th>封面</th>
                                        <th>标题</th>
                                        <th>分类</th>
                                        <th>作者</th>
                                        <th>状态</th>
                                        <th>创建时间</th>
                                        <th>操作</th></tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="vo"}
                                    <tr>
                                        <td>
                                            <input type="checkbox" value="{$vo.id}" lay-skin="primary"></td>
                                        <td>{$vo.id}</td>
                                        <td><img src="{$vo.cover_image|default='/uploads/default/default_cover.jpg'}" style="width: 100%;height: 80px;" /></td>
                                        <td>{$vo.title}</td>
                                        <td>{$vo.cate.cate_name}</td>
                                        <td>{$vo.user_info.username}</td>
                                        <td>{$vo.status}</td>
                                        <td>{$vo.create_time}</td>
                                        <td class="td-manage">
                                            <a href="/admin/post/postAdd?id={$vo.id}" class="layui-btn layui-btn-normal">编辑</a>
                                            <a title="删除" class="layui-btn layui-btn-danger" onclick="post_del(this,'{$vo.id}')" href="javascript:;">
                                                <i class="layui-icon">&#xe640;</i>
                                            </a>
                                            <button  class="layui-btn layui-btn-normal" onclick="pushBaiDu({$vo.id})">推送百度</button>
                                        </td>
                                    </tr>
                                {/volist}
                                </tbody>
                            </table>
                            {$list|raw}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        layui.use(['layer', 'jquery', 'form'], function () {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;

            // 监听全选
            form.on('checkbox(checkall)', function(data){

                if(data.elem.checked){
                    $('tbody input').prop('checked',true);
                }else{
                    $('tbody input').prop('checked',false);
                }
                form.render('checkbox');
            });

            /*状态筛选*/
            form.on('select(postStatus)', function(data){
                location.href = "?status=" + data.value;
                form.render('select');
            });

            /*分类筛选*/
            form.on('select(postCate)', function(data){
                location.href = "?cateId=" + data.value;
                form.render('select');
            });
            /*关键字筛选*/
            $("#btn-search").click(function () {
                var keyword = $("#postKeyword").val();
                location.href = "?keyword=" + keyword;
            })
        });

        //提交百度收录
        function pushBaiDu(id) {
            var domain = location.host;
            var URL;
            var Cts = location.href;
            if(Cts.indexOf("https") >= 0 ) {
                URL = "https://" + domain + "/p/" +id+".html"
            }else{
                URL = "http://" + domain + "/p/" +id+".html"
            }
            $.ajax({
                type:"POST",
                data:{
                    url:URL
                },
                url:"/home/seo/pushBaiDu",
                success:function (e) {
                    if (e.success > 0){
                       layer.msg("成功将："+URL+"提交百度收录，"+"当天可推送剩余：" +e.remain,{icon:1})
                    }else if (e.code == 0){
                        layer.msg(e.msg,{icon:2})
                    } else {
                        layer.msg(e.success,{icon:2})
                    }
                }
            })
        }
        /*文章-删除*/
        function post_del(obj, id) {
            layer.confirm('确认要删除吗？',
            function(index) {
                //发异步删除数据
                $.ajax({
                    type:"POST",
                    data:{
                        post_id:id
                    },
                    url:"/admin/post/delPost",
                    success:function (e) {
                        if(e.code == 1){
                            $(obj).parents("tr").remove();
                            layer.msg(e.msg, {
                                icon: 1,
                                time: 1000
                            });
                        }else{
                            layer.msg(e.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        function delAll() {

            var ids = [];

            // 获取选中的id
            $('tbody input').each(function(index, el) {
                if($(this).prop('checked')){
                    ids.push($(this).val())
                }
            });

            layer.confirm('确认要删除所选文章？',
            function(index) {
                //发异步删除数据
                $.ajax({
                    type:"POST",
                    data:{
                        post_id:ids
                    },
                    url:"/admin/post/delPost",
                    success:function (e) {
                        if(e.code == 1){
                            layer.msg(e.msg, {icon: 1});
                            $(".layui-form-checked").not('.header').parents('tr').remove();
                        }else{
                            layer.msg(e.msg, {icon: 2});
                        }
                    }
                })
            });
        }</script>

</html>